package DuoTai;

public class MyTest {
    public static void main(String[] args) {
        Animal  animal = new Dog();
        speak(animal);

    }

    public static void speak(Animal a){
        if (a instanceof Dog){
            Dog d = (Dog) a;
            d.eat();
        }else if (a instanceof Fish){
            Fish f = (Fish)a;
            f.egg();
        }
    }
}

class Animal{
    public void move(){
        System.out.println("移动");
    }
}
class Dog extends Animal{
    public void move(){
        System.out.println("跑动");
    }
    public void eat(){
        System.out.println("吃东西");
    }
}

class Fish extends Animal{
    public void move(){
        System.out.println("游动");
    }
    public void egg(){
        System.out.println("下蛋");
    }
}

